home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / pds300.arc / PDSORT.DOC < prev    next >
Text File  |  1991-02-09  |  17KB  |  344 lines

  1.                                    PDSORT
  2.                    A Public Domain External Sort Program
  3.  
  4. Author:   Don A. Williams
  5. Version:  3.0.0                                                         |
  6. Date:     February 5, 1991                                              |
  7.  
  8.    ****************************  NOTICE!  **************************
  9.    *   Contrary to the current trend  in  MS-DOS  software  this   *
  10.    *   program,  for  whatever  it is worth,  is NOT copyrighted   *
  11.    *   (with the exception of the runtime library  from  Borland   *
  12.    *   International's  Turbo  C)!  The program,  in whole or in   *
  13.    *   part,  may be used freely in any fashion  or  environment   *
  14.    *   desired.  If  you  find this program to be useful to you,   *
  15.    *   do NOT send any contribution to the author;  in the words   *
  16.    *   of  Rick  Conn,   'Enjoy!'  However,   if  you  make  any   *
  17.    *   improvements,  I would enjoy  receiving  a  copy  of  the   *
  18.    *   modified  source.  I  can  be reached,  usually within 24   *
  19.    *   hours,  by  messages  on  any  of  the  Phoenix  systems,   *
  20.    *   particularly:                                               *
  21.    *                                                               *
  22.    *               Technoids Anonymous     [PCBOARD]               *
  23.    *                   (602) 899-4876   300/1200/2400 bps          *
  24.    *                                                               *
  25.    *   All can be reached through PC Pursuit.                      *
  26.    *                                                               *
  27.    *   or:                                                         *
  28.    *                on GEnie, mail address: DON-WILL               *
  29.    *                on CompuServ:           75410,543              *
  30.    *                                                               *
  31.    *   Every  effort has been made to avoid error and moderately   *
  32.    *   extensive testing has been  performed  on  this  program,   *
  33.    *   however, the author does not warrant it to be fit for any   *
  34.    *   purpose  or  to  be  free  from  error  and disclaims any   *
  35.    *   liability for actual or any other damage arising from the   *
  36.    *   use of this program.                                        *
  37.    *****************************************************************
  38.  
  39. PDSORT is a fully public domain external sort  program,  i.e.  it  can 
  40. sort  files  that  are too big to be wholly contained in memory.  This  |
  41. version of PDSORT contains a fully public domain  implentation  of  an  |
  42. iterative version of qsort(), PDQSORT.C, that is fully compatible with  |
  43. the  ANSI  C  standard run time qsort().  The qsort() routine supplied  |
  44. with most of the C compilers is a  recursive  implementation  that  is  |
  45. slower  and  requires  a  great  deal  more  stack  than the iterative  |
  46. version.  The length of the file that  can  be  sorted  by  PDSORT  is  |
  47. limited  only by the available disk space,  however,  you must have at 
  48. least twice as much free space as the length of the file to be  sorted 
  49. -  PDSORT uses an intermediate file the size of the input file and the 
  50. sorted output file will be the same size as the input file.  
  51.  
  52.  
  53. USAGE: 
  54.  
  55. There are three forms for executing PDSORT:                           
  56.  
  57.     pdsort in_file out_file [option] [max_rec_length] [key_spec ....]
  58.  
  59. and:
  60.  
  61.     pdsort - [option] [max_rec_length] [key_spec...] <in_file >out_file
  62.  
  63. and:                                                                  
  64.                                                                       
  65.     pdsort <in_file >out_file                                         
  66.                                                                       
  67. In the first form,  the input_file specification can be  any  standard 
  68. MS-DOS  file  specification including full path specifications but may 
  69. NOT contain "wild cards".  The output_file specification may  also  be 
  70. any  standard  MS-DOS  file specification not containing "wild cards".  
  71. The input_file and output_file names may be  the  same  but,  in  this 
  72. case,  the input_file will be destroyed by PDSORT  by  overwriting  it 
  73. with  the  input file.  If no max_record_length argument is specified,
  74. PDSORT will use a default of 256 characters/record.  No records in the
  75. input file may exceed the maximum record  length.  If  a  record  that
  76. exceeds  the  maximum  record  length  is  detected in the input file,
  77. PDSORT will issue a message identifying the record and will terminate.
  78.  
  79. In the second form, PDSORT executes as a "filter", reading and sorting 
  80. standard input to produce  standard  output,  both  of  which  may  be 
  81. redirected.  
  82.  
  83.  
  84. In  the  third form,  PDSORT also executes as a "filter",  reading and
  85. sorting standard input to produce standard output,  both of which  may
  86. be  redirected.  The  difference between the second form and the third
  87. form is that the third form uses the default maximum  record  size  of
  88. 256 characters/record and the default sort key of the entire record.  
  89.  
  90. Options:
  91.  
  92. The only options supported by version 2.1.3 of PDSORT are: 
  93.  
  94.     -      A single '-',  delimited by  blanks,  instructs  PDSORT  to 
  95.            operate  as a filter,  taking its input from standard input 
  96.            and sending its output to standard output.  
  97.  
  98.     -tpath The '-t' option allows the user to specify the path for the 
  99.            intermediate file created by PDSORT.  If no  such  path  is 
  100.            specified,  PDSORT  will use the path of the output file as 
  101.            the path of the intermediate file.  If the "filter"  option 
  102.            is selected and no intermediate file path is specified, the 
  103.            intermediate file will be created in the current directory.  
  104.       
  105.     -o     The  '-o'  option  will  suppress all messages except error
  106.            messages.                                                  
  107.  
  108.  
  109. Key Specification:
  110.  
  111. There  may  be  as  many keys specified as you wish.  The file will be 
  112. sorted on the keys in the order in  which  they  are  specified.  Each 
  113. key_spec has one of the following two formats: 
  114.  
  115.     b:l:[field_options]
  116.  
  117. or:
  118.  
  119.     b-e:[field_options]
  120.  
  121. where:
  122.  
  123.     b - Specifies  the  beginning  character  position of the field in 
  124.         decimal;  i.e to sort a field that is in columns 10 through 17 
  125.         of the record, b would be 10.
  126.     l - Specifies the length of the field in characters; i.e to sort a 
  127.         field that is in columns 10 through 17 of the record,  l would 
  128.         be 8 - 10:8[:options].
  129.     e - Specifies the  ending  character  position  of  the  field  in 
  130.         decimal,  inclusive;  i.e to sort a file that is in characters 
  131.         10 through 17 of the record with  this  format  of  the  field 
  132.         specifier would require the e be 17 - 10-17[:options].
  133.  
  134. Field Options:
  135.  
  136.     a - Specifies  that  the  sort on this field is to be in ascending 
  137.         order,  the default if no field option is specified  for  this 
  138.         field.  
  139.  
  140.     d - Specifies  that  the sort on this field is to be in descending 
  141.         order.  
  142.  
  143.     c - Specifies that the sort on this field is to be case sensitive; 
  144.         i.e.  the  word  Abscess"  would  sort  lower  that  the  word 
  145.         "abscess".  A  case  sensitive  sort  is the default if none 
  146.         is specified.  
  147.  
  148.     i - Specifies  that  the  sort  on  this  field  is  to  be   case 
  149.         insensitive.  
  150.  
  151.     c - Specifies that this field is ASCII character data, the default 
  152.         if  not  specified.  Since  PDSORT  2.0.0  supports only ASCII 
  153.         character fields, this option if only for upward compatibility 
  154.         with future version of PDSORT that  may  support  other  field 
  155.         types such as integer (numeric).  
  156.  
  157.  
  158.  
  159. Error Levels                                                         
  160.                                                                      
  161. If PDSORT terminates due to an error condition, it will set the MS-DOS
  162. ERRORLEVEL as follows:                                                
  163.                                                                       
  164.      1·-·Invalid command argument or option.                          
  165.      2·-·Unable  to open the specified input file.  Possibly incorrect
  166.          file name.                                                   
  167.      3·-·Input/Output error on input file.                            
  168.      4·-·A record in the input file exceeds the maximum length        
  169.      5·-·Insufficient space on output disk.                           
  170.      6·-·Insufficient space on intermediate disk.                     
  171.      7·-·Unable to create output file.                                
  172.      8·-·Input/Output error on output file.                           
  173.      9·-·Unable to create intermediate file.                          
  174.     10·-·Input/Output error on intermediate file.                    
  175.     11·-·Reopen failure!                                             
  176.     12·-·Insufficient memory.                                        
  177.                                                                      
  178. On normal termination, the ERRORLEVEL will be set to 0.              
  179.  
  180.  
  181.  
  182. Examples:
  183.  
  184. Assume  a  file,  named  FILELIST,  that contains a list of file name, 
  185. sizes, date/times, and paths, such as can be created by NUFIND: 
  186.  
  187.     a----w           27,974 90-04-30  6:30 c:\acelst.430
  188.     a----w           28,196 90-05-21  5:05 c:\acelst.521
  189.     a----w           28,238 90-05-25  5:41 c:\acelst.525
  190.     a----w           26,705 90-05-25  5:39 c:\acelst.lst
  191.     a----w          128,537 90-05-25  5:41 c:\acelst.zip
  192.     a----w              904 90-05-23  4:33 c:\autoexec.bat
  193.     a----w           35,840 89-06-30 12:16 c:\command.com
  194.     a----w               46 89-08-20  3:53 c:\config.cal
  195.     a----w              284 90-05-21 19:52 c:\config.sys
  196.     a----w            2,128 90-05-23  4:32 c:\configur.dat
  197.     ------           39,385 89-07-14 12:00 c:\drbdos.sys
  198.     ------           18,304 89-06-30 12:16 c:\drbios.sys
  199.     ---sh-            4,096 90-03-18 13:22 c:\drildr.sys
  200.     a----w              167 89-10-11  7:56 c:\dsas.cmd
  201.     a----w              102 86-11-04  9:14 c:\ed.def
  202.     a----w           50,326 86-10-02 21:34 c:\ed.hlp
  203.     a----w            3,362 86-06-09 13:10 c:\fakey.com
  204.     a----w                0 90-05-23  7:54 c:\ftf.dat
  205.     a----w           12,275 85-06-16 18:12 c:\helpe.def
  206.     a----w               79 89-05-17  5:02 c:\indent.pro
  207.     a----w            7,122 90-01-15  1:00 c:\lineend.com
  208.     a----w            1,060 90-05-25  9:40 c:\mark0
  209.     a--sh-               41 90-05-25  9:40 c:\mirorsav.fil
  210.     a-----           41,472 90-05-25  9:40 c:\mirror.bak
  211.     a-----           41,472 90-05-25  9:40 c:\mirror.fil
  212.     a----w              237 90-02-06  5:09 c:\model
  213.     a----w           12,432 87-03-10 13:34 c:\mouse.sys
  214.     a----w            2,507 87-10-21 13:45 c:\nansi.sys
  215.     a----w              251 87-07-16 18:06 c:\newkbios.com
  216.     a----w            6,094 89-11-21 15:03 c:\no101.com
  217.     a----w            2,836 90-05-03  7:21 c:\phone.dir
  218.     a----w            2,670 89-12-01 17:00 c:\phones
  219.     a----w            2,010 90-03-18 11:14 c:\pushdir.stk
  220.     a----w               90 89-09-05  3:29 c:\ruler.def
  221.     a----w            1,465 87-04-22 10:38 c:\ruler.prt
  222.     a----w           53,632 85-05-03 14:09 c:\sk.hlp
  223.     a----w           33,611 86-12-05  9:21 c:\skn.com
  224.     a----w           18,825 90-01-15  1:00 c:\synonym.com
  225.     a----w            1,610 90-05-13 16:15 c:\synonym.def
  226.     a----w           14,426 90-05-19 17:38 c:\utils
  227.     a----w            1,060 90-05-25 12:17 c:\mark1
  228.  
  229. The file path name begins in column 40 and  extends  through  80,  the 
  230. file size is in columns 15 through 23,  inclusive, the file date is in 
  231. columns 25 through 32,  inclusive,  and the file time is in columns 34 
  232. through 39, inclusive.  
  233.  
  234. A PDSORT command to sort this list so that the largest files are first 
  235. and files of equal size are in name order would require the  following 
  236. command: 
  237.  
  238.     pdsort filelist fileout 80 15-23:d 44-80
  239.  
  240. giving the following list in the file FILEOUT:
  241.  
  242.     a----w          128,537 90-05-25  5:41 c:\acelst.zip
  243.     a----w           53,632 85-05-03 14:09 c:\sk.hlp
  244.     a----w           50,326 86-10-02 21:34 c:\ed.hlp
  245.     a-----           41,472 90-05-25  9:40 c:\mirror.bak
  246.     a-----           41,472 90-05-25  9:40 c:\mirror.fil
  247.     ------           39,385 89-07-14 12:00 c:\drbdos.sys
  248.     a----w           35,840 89-06-30 12:16 c:\command.com
  249.     a----w           33,611 86-12-05  9:21 c:\skn.com
  250.     a----w           28,238 90-05-25  5:41 c:\acelst.525
  251.     a----w           28,196 90-05-21  5:05 c:\acelst.521
  252.     a----w           27,974 90-04-30  6:30 c:\acelst.430
  253.     a----w           26,705 90-05-25  5:39 c:\acelst.lst
  254.     a----w           18,825 90-01-15  1:00 c:\synonym.com
  255.     ------           18,304 89-06-30 12:16 c:\drbios.sys
  256.     a----w           14,426 90-05-19 17:38 c:\utils
  257.     a----w           12,432 87-03-10 13:34 c:\mouse.sys
  258.     a----w           12,275 85-06-16 18:12 c:\helpe.def
  259.     a----w            7,122 90-01-15  1:00 c:\lineend.com
  260.     a----w            6,094 89-11-21 15:03 c:\no101.com
  261.     ---sh-            4,096 90-03-18 13:22 c:\drildr.sys
  262.     a----w            3,362 86-06-09 13:10 c:\fakey.com
  263.     a----w            2,836 90-05-03  7:21 c:\phone.dir
  264.     a----w            2,670 89-12-01 17:00 c:\phones
  265.     a----w            2,507 87-10-21 13:45 c:\nansi.sys
  266.     a----w            2,128 90-05-23  4:32 c:\configur.dat
  267.     a----w            2,010 90-03-18 11:14 c:\pushdir.stk
  268.     a----w            1,610 90-05-13 16:15 c:\synonym.def
  269.     a----w            1,465 87-04-22 10:38 c:\ruler.prt
  270.     a----w            1,060 90-05-25  9:40 c:\mark0
  271.     a----w            1,060 90-05-25 12:17 c:\mark1
  272.     a----w              904 90-05-23  4:33 c:\autoexec.bat
  273.     a----w              284 90-05-21 19:52 c:\config.sys
  274.     a----w              251 87-07-16 18:06 c:\newkbios.com
  275.     a----w              237 90-02-06  5:09 c:\model
  276.     a----w              167 89-10-11  7:56 c:\dsas.cmd
  277.     a----w              102 86-11-04  9:14 c:\ed.def
  278.     a----w               90 89-09-05  3:29 c:\ruler.def
  279.     a----w               79 89-05-17  5:02 c:\indent.pro
  280.     a----w               46 89-08-20  3:53 c:\config.cal
  281.     a--sh-               41 90-05-25  9:40 c:\mirorsav.fil
  282.     a----w                0 90-05-23  7:54 c:\ftf.dat
  283.  
  284. The same sort could be accomplished by the command:
  285.  
  286.     pdsort - 80 15-23:d 40-80 <filelist >fileout
  287.  
  288.  
  289. Now suppose that you wanted the most recently modified or  created  files 
  290. first.  The following command would do that:
  291.  
  292.     pdsort filelist fileout 80 25-32:d 34-39:d 40-80
  293.  
  294. giving the following list in FILEOUT:
  295.  
  296.     a----w            1,060 90-05-25 12:17 c:\mark1
  297.     a----w            1,060 90-05-25  9:40 c:\mark0
  298.     a--sh-               41 90-05-25  9:40 c:\mirorsav.fil
  299.     a-----           41,472 90-05-25  9:40 c:\mirror.bak
  300.     a-----           41,472 90-05-25  9:40 c:\mirror.fil
  301.     a----w           28,238 90-05-25  5:41 c:\acelst.525
  302.     a----w          128,537 90-05-25  5:41 c:\acelst.zip
  303.     a----w           26,705 90-05-25  5:39 c:\acelst.lst
  304.     a----w                0 90-05-23  7:54 c:\ftf.dat
  305.     a----w              904 90-05-23  4:33 c:\autoexec.bat
  306.     a----w            2,128 90-05-23  4:32 c:\configur.dat
  307.     a----w              284 90-05-21 19:52 c:\config.sys
  308.     a----w           28,196 90-05-21  5:05 c:\acelst.521
  309.     a----w           14,426 90-05-19 17:38 c:\utils
  310.     a----w            1,610 90-05-13 16:15 c:\synonym.def
  311.     a----w            2,836 90-05-03  7:21 c:\phone.dir
  312.     a----w           27,974 90-04-30  6:30 c:\acelst.430
  313.     ---sh-            4,096 90-03-18 13:22 c:\drildr.sys
  314.     a----w            2,010 90-03-18 11:14 c:\pushdir.stk
  315.     a----w              237 90-02-06  5:09 c:\model
  316.     a----w            7,122 90-01-15  1:00 c:\lineend.com
  317.     a----w           18,825 90-01-15  1:00 c:\synonym.com
  318.     a----w            2,670 89-12-01 17:00 c:\phones
  319.     a----w            6,094 89-11-21 15:03 c:\no101.com
  320.     a----w              167 89-10-11  7:56 c:\dsas.cmd
  321.     a----w               90 89-09-05  3:29 c:\ruler.def
  322.     a----w               46 89-08-20  3:53 c:\config.cal
  323.     ------           39,385 89-07-14 12:00 c:\drbdos.sys
  324.     a----w           35,840 89-06-30 12:16 c:\command.com
  325.     ------           18,304 89-06-30 12:16 c:\drbios.sys
  326.     a----w               79 89-05-17  5:02 c:\indent.pro
  327.     a----w            2,507 87-10-21 13:45 c:\nansi.sys
  328.     a----w              251 87-07-16 18:06 c:\newkbios.com
  329.     a----w            1,465 87-04-22 10:38 c:\ruler.prt
  330.     a----w           12,432 87-03-10 13:34 c:\mouse.sys
  331.     a----w           33,611 86-12-05  9:21 c:\skn.com
  332.     a----w              102 86-11-04  9:14 c:\ed.def
  333.     a----w           50,326 86-10-02 21:34 c:\ed.hlp
  334.     a----w            3,362 86-06-09 13:10 c:\fakey.com
  335.     a----w           12,275 85-06-16 18:12 c:\helpe.def
  336.     a----w           53,632 85-05-03 14:09 c:\sk.hlp
  337.  
  338. Again,  the same sort could have been accomplished  by  the  following 
  339. command: 
  340.  
  341.     pdsort - 25-32:d 34-39:d 40-80 <filelist >fileout
  342.  
  343.  
  344.